import { defineStore } from 'pinia'
const shop = defineStore('shops', {
    state() {
        return {
            arr: [
                {
                    id: 1,
                    title: "适用于6-7岁儿童玩具,抽盲盒，随机抽奖，抽到就拿走",
                    price: 18,
                    img: "img/1.png.crdownload",
                    num: 1,
                    status: false
                },
                {
                    id: 2,
                    title: "适用于6-7岁儿童玩具,抽盲盒，随机抽奖，抽到就拿走",
                    price: 18,
                    img: "img/1.png.crdownload",
                    num: 1,
                    status: false
                },
                {
                    id: 3,
                    title: "适用于6-7岁儿童玩具,抽盲盒，随机抽奖，抽到就拿走",
                    price: 18,
                    img: "img/1.png.crdownload",
                    num: 1,
                    status: false
                },
                {
                    id: 4,
                    title: "适用于6-7岁儿童玩具,抽盲盒，随机抽奖，抽到就拿走",
                    price: 18,
                    img: "img/1.png.crdownload",
                    num: 1,
                    status: false
                },
                {
                    id: 5,
                    title: "适用于6-7岁儿童玩具,抽盲盒，随机抽奖，抽到就拿走",
                    price: 18,
                    img: "img/1.png.crdownload",
                    num: 1,
                    status: false
                },
                {
                    id: 6,
                    title: "适用于6-7岁儿童玩具,抽盲盒，随机抽奖，抽到就拿走",
                    price: 18,
                    img: "img/1.png.crdownload",
                    num: 1,
                    status: false
                },
            ]
        }
    },
    actions: {
        changeAll(done) {
            this.arr.forEach(item => { item.status = done })
        }
    },
    getters: {
        total() {
            let sum = 0
            this.arr.forEach(item => {
                if (item.status) {
                    sum += item.num * item.price
                }
            })
            console.log(sum);
            return sum
        }
    },
})
export default shop